﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace eProject.View
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            new SplashScreen("splashscreen.png").Show(true);
            var path = e.Args.Count() > 0 ? e.Args[0] : null;
            if (!String.IsNullOrEmpty(path) && File.Exists(path))
            {
               new MainWindow(path).Show();                
            } else 
            {
                new MainWindow().Show();
            }

        }

    }

    public class ExtractErrorMessageConverter : IValueConverter
    {
        public static readonly ExtractErrorMessageConverter Instance = new ExtractErrorMessageConverter();

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var list = value as IList<ValidationError>;
            if (list == null || list.Count() == 0) return null;

            return list[0].ErrorContent;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
